package paf.ui;

import java.io.IOException;
import java.util.ArrayList;

import javax.swing.JPanel;

import org.xml.sax.SAXException;

import paf.exporter.ExportFacade;
import paf.exporter.FileInterface;
import paf.importerandtranslators.FileStrategy;
import paf.importerandtranslators.ImportFacade;
import paf.model.DiagramExpressionModel;
import paf.model.FileStrategyContainer;

public class UiController {

	private static UiController uiController;
	private MainFrame mainFrame;
	private DiagramExpressionModel model;
	private ImportFacade importFacade;
	private ExportFacade exportFacade;
	
	private UiController() {
		this.model = DiagramExpressionModel.get();
		this.importFacade = new ImportFacade();
		this.exportFacade = new ExportFacade();
		mainFrame = new MainFrame(new ManageConnectionsUI(), this);
	}
	
	public static UiController get() {
		if(uiController == null) uiController = new UiController();
		return uiController;
	}
	
	public void fileImportNext(ArrayList<FileStrategyContainer> arrFSC) {
		for(FileStrategyContainer fsc : arrFSC) {
			try {
				importFacade.importFile(fsc.getFileStrategy(), fsc.getFile());
			} catch (SAXException e) {
				System.out.println(e.getMessage());
				e.printStackTrace();
			} catch (IOException e) {
				System.out.println(e.getMessage());
				e.printStackTrace();
			}
		}
		
		mainFrame.setPage(new ManageConnectionsUI());
	}

	public ArrayList<FileStrategy> getFileTypes() {
		return importFacade.getFileStrategies();
	}
	
	public ArrayList<FileInterface> getFileInterfaces() {
		return exportFacade.getFileInterfaces();
	}
	
	public void setPage(JPanel j) {
		mainFrame.setPage(j);
	}
}
